<?php
// 屏蔽错误程度E_All显示致命错误  ： E_ERROR屏蔽所有错误   默认显示警告和致命错误
error_reporting(E_ERROR);


/**
 * Created by qinpeizhou.
 * Date: 2018/5/13
 * Time: 3:14
 * Email : 1031219129@qq.com
 * 公共函数类库
 */

/**
 * 简洁的打印函数
 * @param $var
 * @param bool $exit
 */
function dump($var, $exit = true) {
    echo '<pre>';
    print_r ( $var );
    echo '</pre>';
    if ($exit) {
        die ();
    }
}


/**
 * 通用化API接口数据输出
 * author qinpeizhou
 * @param $status
 * @param $message
 * @param array $data
 * @param int $httpCode
 * @return \think\response\Json
 */
function show($message,$data=[],$httpCode=200){
    $data = [
        'code' => $httpCode,
        'message' => $message,
        'data' => (object)$data
    ];
    echo json_encode($data,$httpCode);
}


/**
 * 实例化redis
 * @return \Predis\Client
 */
function p_redis(){
    // 加载redis配置
    $settings = parse_ini_file(dirname(__FILE__).'/../extra/myconfig.php');
    $host = $settings["host"];
    $port = $settings["port"];
    $dataBase = $settings["dataBase"];
    $server = [
        "host"=>$host,
        'port'=>$port,
        'dataBase'=>$dataBase
    ];
    $redis = new \Predis\Client($server);
    return $redis;
}
